# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=extremetuxracer
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.3
pkgrel=2
pkgdesc="Downhill racing game starring Tux (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://sourceforge.net/projects/extremetuxracer"
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-sfml"
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("https://downloads.sourceforge.net/${_realname}/etr-${pkgver}.tar.xz"
        "0001-relocate.patch"
        "pathtools.c"
        "pathtools.h")
sha256sums=('2ee42f3f5fc2f8d49aa75056eb116f6cab84d6564120e6961ae5927367245113'
            '99200769921b20ad281fca39125a50fdbe88c8641ad30aa40fae69d3a87f9717'
            '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd'
            '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6')

prepare() {
  test ! -d "${startdir}/../mingw-w64-pathtools" || {
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.c" "${srcdir}/pathtools.c" &&
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.h" "${srcdir}/pathtools.h"
  } || exit 1

  cd etr-${pkgver}
  cp -fHv "${srcdir}"/pathtools.[ch] src/
  patch -p1 -i "${srcdir}/0001-relocate.patch"
  ./autogen.sh
}

build() {
  cd "${srcdir}/etr-${pkgver}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../"etr-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}"

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install
}
